<?php
class ModulePaymentOrderVo extends SzAbstractMySqlVo
{

    private $orderId;
    private $userId;
    private $platformToken;
    private $paymentDefId;
    private $orderTime;
    private $completeTime;
    private $status;
    private $extra;
    private $price;

    /**
     * 如果应用设置了包裹上限且用户充值购买道具时, 需要记录下溢出的道具, 返回给应用, 由应用自行处理
     *
     * <pre>
     * 从ModuleItemVoList对象中直接读取到溢出道具列表
     *
     * array(
     *      array($itemDefId => $count),
     *      ...
     * )
     * </pre>
     */
    protected $exceededItemList = array();

    /**
     * Initialize ModulePaymentOrderVo.
     *
     * @param $orderId
     * @param $userId
     * @param $platformToken
     * @param $paymentDefId
     * @param $orderTime
     * @param $completeTime
     * @param $status
     * @param $extra
     * @param $price
     * @param boolean $isInsert default false, means for now this vo is initialized not for insert process
     * @return ModulePaymentOrderVo
     */
    public function __construct($orderId, $userId, $platformToken, $paymentDefId, $orderTime, $completeTime, $status, $extra, $price, $isInsert = false) {
        $this->orderId = $orderId;
        $this->userId = $userId;
        $this->platformToken = $platformToken;
        $this->paymentDefId = $paymentDefId;
        $this->orderTime = $orderTime;
        $this->completeTime = $completeTime;
        $this->status = $status;
        $this->extra = json_decode($extra, true);
        $this->price = $price;

        $this->isInsert = $isInsert;
        $this->voClassName = 'ModulePaymentOrderVo';
        $this->ormName = 'ModulePaymentOrder';
    }

    /**
     * @see SzAbstractVo::toArray
     */
    public function toArray($needEncode = false)
    {
        return array(
            'orderId' => $this->getOrderId(),
            'userId' => $this->getUserId(),
            'platformToken' => $this->getPlatformToken(),
            'paymentDefId' => $this->getPaymentDefId(),
            'orderTime' => $this->getOrderTime(),
            'completeTime' => $this->getCompleteTime(),
            'status' => $this->getStatus(),
            'extra' => ($needEncode) ? $this->getExtra() : $this->getRawExtra(),
            'price' => $this->getPrice(),
        );
    }

    /**
     * @see SzAbstractVo::toEntireArray
     */
    public function toEntireArray($needEncode = false)
    {
        return array(
            'orderId' => $this->getOrderId(),
            'userId' => $this->getUserId(),
            'platformToken' => $this->getPlatformToken(),
            'paymentDefId' => $this->getPaymentDefId(),
            'orderTime' => $this->getOrderTime(),
            'completeTime' => $this->getCompleteTime(),
            'status' => $this->getStatus(),
            'extra' => ($needEncode) ? $this->getExtra() : $this->getRawExtra(),
            'price' => $this->getPrice(),
        );
    }

    /**
     * @see SzAbstractVo::toPureArray
     */
    public function toPureArray()
    {
        return array(
            $this->getOrderId(),
            $this->getUserId(),
            $this->getPlatformToken(),
            $this->getPaymentDefId(),
            $this->getOrderTime(),
            $this->getCompleteTime(),
            $this->getStatus(),
            $this->getExtra(),
            $this->getPrice(),
        );
    }

    public function getOrderId()
    {
        return $this->orderId;
    }

    public function setOrderId($val)
    {
        $this->saveColumnStatus(0, $this->orderId);
        $this->orderId = $val;
    }

    public function getUserId()
    {
        return $this->userId;
    }

    public function setUserId($val)
    {
        $this->saveColumnStatus(1, $this->userId);
        $this->userId = $val;
    }

    public function getPlatformToken()
    {
        return $this->platformToken;
    }

    public function setPlatformToken($val)
    {
        $this->saveColumnStatus(2, $this->platformToken);
        $this->platformToken = $val;
    }

    public function getPaymentDefId()
    {
        return $this->paymentDefId;
    }

    public function setPaymentDefId($val)
    {
        $this->saveColumnStatus(3, $this->paymentDefId);
        $this->paymentDefId = $val;
    }

    public function getOrderTime()
    {
        return $this->orderTime;
    }

    public function setOrderTime($val)
    {
        $this->saveColumnStatus(4, $this->orderTime);
        $this->orderTime = $val;
    }

    public function getCompleteTime()
    {
        return $this->completeTime;
    }

    public function setCompleteTime($val)
    {
        $this->saveColumnStatus(5, $this->completeTime);
        $this->completeTime = $val;
    }

    public function getStatus()
    {
        return $this->status;
    }

    public function setStatus($val)
    {
        $this->saveColumnStatus(6, $this->status);
        $this->status = $val;
    }

    public function getExtra()
    {
        return json_encode($this->extra);
    }

    public function getRawExtra()
    {
        return $this->extra;
    }

    public function setExtra($val)
    {
        $encodedLength = SzUtility::strLen(json_encode($val));
        if ($encodedLength > 256) {
            SzLogger::get()->error('[ModulePaymentOrderVo] The length of column extra exceed the limit, length / limit: ' . $encodedLength . ' / 256');
            throw new SzException(10522, array('ModulePaymentOrderVo', '256', $encodedLength));
        } else if ($encodedLength > 230) {
            SzLogger::get()->warn('[ModulePaymentOrderVo] The length of column extra exceed the warning level, length / limit: ' . $encodedLength . ' / 256');
        }
        $this->saveColumnStatus(7, $this->extra);
        $this->extra = $val;
    }

    public function getPrice()
    {
        return $this->price;
    }

    public function setPrice($val)
    {
        $this->saveColumnStatus(8, $this->price);
        $this->price = $val;
    }

    /**
     * @param array $exceededList
     * array(
     *      array($itemDefId => $count),
     *      ...
     * )
     */
    public function setExceededItemList($exceededList)
    {
        $this->exceededItemList = $exceededList;
    }

    /**
     * @return array
     * array(
     *      array($itemDefId => $count),
     *      ...
     * )
     */
    public function getExceededItemList()
    {
        return $this->exceededItemList;
    }
}